package com.DAO;

import com.Util.Sql;
import com.Module.Room;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Roominfo implements Sql {
    public List<Room> list=new ArrayList<>();
    @Override
    public void select() {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            String sql="select * from  room";
            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                int roomid     =resultSet.getInt("roomid");
                String roomtype   =resultSet.getString("roomtype");
                int currpeople =resultSet.getInt("currpeople");
                int rstste     =resultSet.getInt("rstste");
                int street     =resultSet.getInt("street");
                int id         =resultSet.getInt("id");
                Room room=new Room(roomid,roomtype,currpeople,rstste,street,id);
                list.add(room);
            }
            databaseConnection.release(connection,statement,resultSet);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public List<Object> select(String id) {
        return null;
    }

    @Override
    public int update() {
        return 0;
    }

    @Override
    public int update(Object obj) {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        int ans = 0;
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            Room room=(Room) obj;
            String sql="INSERT INTO room VALUES("+room.getRoomid()+",'"+room.getRoomtype()+"',"+room.getCurrpeople()+","+room.getRstste()+","+room.getStreet()+","+room.getId()+")";
            ans=statement.executeUpdate(sql);
            databaseConnection.release(connection,statement);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ans;
    }

    @Override
    public int delete(Object obj) {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        int ans = 0;
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            Room room=(Room) obj;
            String sql="UPDATE  menber SET enddate='' where mid=";
            ans=statement.executeUpdate(sql);
            databaseConnection.release(connection,statement);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ans;
    }


    @Override
    public int modify(Object obj) {
        return 0;
    }
}
